package com.usefullc.system.configuration.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.core.convert.converter.Converter;

import java.io.IOException;

@JsonComponent
public  class BooleanSerializer extends JsonSerializer<Boolean> implements Converter<Boolean, String> {
    @Override
    public void serialize(Boolean value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeStartObject(convert(value));
    }

    @Override
    public String convert(Boolean source) {
        if(source){
            return "1";
        }else{
            return "0";
        }
    }



}
